﻿<template>
  <div>
    <a-card :bordered="false" :bodyStyle="tstyle">

      <div class="table-page-search-wrapper" v-if="hasPerm('IcOutList:page')">
        <a-form layout="inline">
          <a-row :gutter="48">
            <a-col :md="8" :sm="24">
              <a-form-item label="AUTO_NO ">
                <a-input v-model="queryParam.autoNo" allow-clear placeholder="请输入AUTO_NO "/>
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24">
              <a-form-item label="IC_NO ">
                <a-input v-model="queryParam.icNo" allow-clear placeholder="请输入IC_NO "/>
              </a-form-item>
            </a-col><template v-if="advanced">
              <a-col :md="8" :sm="24">
                <a-form-item label="PATIENT_NAME ">
                  <a-input v-model="queryParam.patientName" allow-clear placeholder="请输入PATIENT_NAME "/>
                </a-form-item>
              </a-col><a-col :md="8" :sm="24">
                <a-form-item label="OPER_DATE ">
                  <a-date-picker style="width: 100%" placeholder="请选择OPER_DATE " v-model="queryParam.operDateDate" @change="onChangeoperDate"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="OPER_CODE ">
                  <a-input v-model="queryParam.operCode" allow-clear placeholder="请输入OPER_CODE "/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="OPER_NAME ">
                  <a-input v-model="queryParam.operName" allow-clear placeholder="请输入OPER_NAME "/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="OUT_FEE ">
                  <a-input v-model="queryParam.outFee" allow-clear placeholder="请输入OUT_FEE "/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="OPER_STYLE ">
                  <a-input v-model="queryParam.operStyle" allow-clear placeholder="请输入OPER_STYLE "/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="REMARK ">
                  <a-input v-model="queryParam.remark" allow-clear placeholder="请输入REMARK "/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="OPER_FROM ">
                  <a-input v-model="queryParam.operFrom" allow-clear placeholder="请输入OPER_FROM "/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="RCPT_NO ">
                  <a-input v-model="queryParam.rcptNo" allow-clear placeholder="请输入RCPT_NO "/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="REBATE_TYPE ">
                  <a-input v-model="queryParam.rebateType" allow-clear placeholder="请输入REBATE_TYPE "/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="IC_TYPE ">
                  <a-input v-model="queryParam.icType" allow-clear placeholder="请输入IC_TYPE "/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="IC_UNION_CODE ">
                  <a-input v-model="queryParam.icUnionCode" allow-clear placeholder="请输入IC_UNION_CODE "/>
                </a-form-item>
              </a-col><a-col :md="8" :sm="24">
                <a-form-item label="APP_OPER_DATE ">
                  <a-date-picker style="width: 100%" placeholder="请选择APP_OPER_DATE " v-model="queryParam.appOperDateDate" @change="onChangeappOperDate"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="APP_ORDER_CODE ">
                  <a-input v-model="queryParam.appOrderCode" allow-clear placeholder="请输入APP_ORDER_CODE "/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="PATIENT_NAME_UNION ">
                  <a-input v-model="queryParam.patientNameUnion" allow-clear placeholder="请输入PATIENT_NAME_UNION "/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="CRM_ID ">
                  <a-input v-model="queryParam.crmId" allow-clear placeholder="请输入CRM_ID "/>
                </a-form-item>
              </a-col>            </template>

            <a-col :md="8" :sm="24" >
              <span class="table-page-search-submitButtons">
                <a-button type="primary" @click="$refs.table.refresh(true)" >查询</a-button>
                <a-button style="margin-left: 8px" @click="() => queryParam = {}">重置</a-button>
                <a @click="toggleAdvanced" style="margin-left: 8px"> {{ advanced ? '收起' : '展开' }}
                  <a-icon :type="advanced ? 'up' : 'down'"/>
                </a>
              </span>
            </a-col>

          </a-row>
        </a-form>
      </div>
    </a-card>
    <a-card :bordered="false">
      <s-table
        ref="table"
        :columns="columns"
        :data="loadData"
        :alert="true"
        :rowKey="(record) => record.iD"
        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }">
        <template class="table-operator" slot="operator" v-if="hasPerm('IcOutList:add')" >
          <a-button type="primary" v-if="hasPerm('IcOutList:add')" icon="plus" @click="$refs.addForm.add()">新增会员消费</a-button>
        </template>
        <span slot="action" slot-scope="text, record">
          <a v-if="hasPerm('IcOutList:edit')" @click="$refs.editForm.edit(record)">编辑</a>
          <a-divider type="vertical" v-if="hasPerm('IcOutList:edit') & hasPerm('IcOutList:delete')"/>
          <a-popconfirm v-if="hasPerm('IcOutList:delete')" placement="topRight" title="确认删除？" @confirm="() => IcOutListDelete(record)">
            <a>删除</a>
          </a-popconfirm>
        </span>
      </s-table>
      <add-form ref="addForm" @ok="handleOk" />
      <edit-form ref="editForm" @ok="handleOk" />
    </a-card>
  </div>
</template>
<script>
  import { STable } from '@/components'
  import moment from 'moment'
  import { IcOutListPage, IcOutListDelete } from '@/api/modular/main/IcOutListManage'
  import addForm from './addForm.vue'
  import editForm from './editForm.vue'
  export default {
    components: {
      STable,
      addForm,
      editForm
    },
    data () {
      return {
        advanced: false, // 高级搜索 展开/关闭
        queryParam: {},
        columns: [
          {
            title: 'IC_NO ',
            align: 'center',
            dataIndex: 'icNo'
          },
          {
            title: 'PATIENT_NAME ',
            align: 'center',
            dataIndex: 'patientName'
          },
          {
            title: 'OPER_DATE ',
            align: 'center',
            dataIndex: 'operDate'
          },
          {
            title: 'OPER_CODE ',
            align: 'center',
            dataIndex: 'operCode'
          },
          {
            title: 'OPER_NAME ',
            align: 'center',
            dataIndex: 'operName'
          },
          {
            title: 'OUT_FEE ',
            align: 'center',
            dataIndex: 'outFee'
          },
          {
            title: 'OPER_STYLE ',
            align: 'center',
            dataIndex: 'operStyle'
          },
          {
            title: 'REMARK ',
            align: 'center',
            dataIndex: 'remark'
          },
          {
            title: 'OPER_FROM ',
            align: 'center',
            dataIndex: 'operFrom'
          },
          {
            title: 'RCPT_NO ',
            align: 'center',
            dataIndex: 'rcptNo'
          },
          {
            title: 'REBATE_TYPE ',
            align: 'center',
            dataIndex: 'rebateType'
          },
          {
            title: 'IC_TYPE ',
            align: 'center',
            dataIndex: 'icType'
          },
          {
            title: 'IC_UNION_CODE ',
            align: 'center',
            dataIndex: 'icUnionCode'
          },
          {
            title: 'APP_OPER_DATE ',
            align: 'center',
            dataIndex: 'appOperDate'
          },
          {
            title: 'APP_ORDER_CODE ',
            align: 'center',
            dataIndex: 'appOrderCode'
          },
          {
            title: 'PATIENT_NAME_UNION ',
            align: 'center',
            dataIndex: 'patientNameUnion'
          },
          {
            title: 'CRM_ID ',
            align: 'center',
            dataIndex: 'crmId'
          }
        ],
        tstyle: { 'padding-bottom': '0px', 'margin-bottom': '10px' },
        // 加载数据方法 必须为 Promise 对象
        loadData: parameter => {
          return IcOutListPage(Object.assign(parameter, this.switchingDate())).then((res) => {
            return res.data
          })
        },
        selectedRowKeys: [],
        selectedRows: []
      }
    },
    created () {
      if (this.hasPerm('IcOutList:edit') || this.hasPerm('IcOutList:delete')) {
        this.columns.push({
          title: '操作',
          width: '150px',
          dataIndex: 'action',
          scopedSlots: { customRender: 'action' }
        })
      }
    },
    methods: {
      moment,
      /**
       * 查询参数组装
       */
      switchingDate () {
        const queryParamoperDate = this.queryParam.operDateDate
        if (queryParamoperDate != null) {
            this.queryParam.operDate = moment(queryParamoperDate).format('YYYY-MM-DD')
            if (queryParamoperDate.length < 1) {
                delete this.queryParam.operDate
            }
        }
        const queryParamappOperDate = this.queryParam.appOperDateDate
        if (queryParamappOperDate != null) {
            this.queryParam.appOperDate = moment(queryParamappOperDate).format('YYYY-MM-DD')
            if (queryParamappOperDate.length < 1) {
                delete this.queryParam.appOperDate
            }
        }
        const obj = JSON.parse(JSON.stringify(this.queryParam))
        return obj
      },
      IcOutListDelete (record) {
        IcOutListDelete(record).then((res) => {
          if (res.success) {
            this.$message.success('删除成功')
            this.$refs.table.refresh()
          } else {
            this.$message.error('删除失败') // + res.message
          }
        })
      },
      toggleAdvanced () {
        this.advanced = !this.advanced
      },
      onChangeoperDate(date, dateString) {
        this.operDateDateString = dateString
      },
      onChangeappOperDate(date, dateString) {
        this.appOperDateDateString = dateString
      },
      handleOk () {
        this.$refs.table.refresh()
      },
      onSelectChange (selectedRowKeys, selectedRows) {
        this.selectedRowKeys = selectedRowKeys
        this.selectedRows = selectedRows
      }
    }
  }
</script>
<style lang="less">
  .table-operator {
    margin-bottom: 18px;
  }
  button {
    margin-right: 8px;
  }
</style>
